import com.shopping.FruitType;
import com.shopping.factory.PromotionFactory;
import com.shopping.handle.impl.FruitSupermarket;

import java.math.BigDecimal;

public class Main {
    public static void main(String[] args) {
        testUserA();
//        testUserAIllegal();
        testUserB();
        testUserC();
        testUserD();
    }
    public static void testUserA() {
        FruitSupermarket userA = new FruitSupermarket.Shopping()
                .buy(FruitType.APPLE, 1)
                .buy(FruitType.STRAWBERRY, 3)
                .build();
        BigDecimal totalAmount = userA.checkout();
        System.out.println("用户A需要付款：" + totalAmount);
    }

//    用户A案例非法情况测试用例
    public static void testUserAIllegal() {
        FruitSupermarket userA = new FruitSupermarket.Shopping()
                .buy(FruitType.APPLE, 1)
                .buy(FruitType.STRAWBERRY, 3)
                .buy(FruitType.STRAWBERRY,-1)//异常情况
                .build();
        BigDecimal totalAmount = userA.checkout();
        System.out.println("用户A需要付款：" + totalAmount);
    }


    //    增加芒果
    public static void testUserB() {
        FruitSupermarket userB = new FruitSupermarket.Shopping()
                .buy(FruitType.APPLE, 1)
                .buy(FruitType.STRAWBERRY, 3)
                .buy(FruitType.MANGO, 2)
                .build();

        BigDecimal totalAmount = userB.checkout();
        System.out.println("用户B需要付款：" + totalAmount);
    }

    //    模拟打折
    public static void testUserC() {
        FruitSupermarket userC = new FruitSupermarket.Shopping()
                .buy(FruitType.APPLE, 1)//苹果打8折 测试前需要开启促销商品初始化
                .buy(FruitType.STRAWBERRY, 3)
                .buy(FruitType.MANGO, 2)
                .build();

        BigDecimal totalAmount = userC.checkout();
        System.out.println("用户C需要付款：" + totalAmount);
    }

//    模拟促销活动 满100减10
    public static void testUserD() {
        String DEFAULT_PROMOTION = "COUPON";//促销活动名称
        FruitSupermarket userD = new FruitSupermarket.Shopping()
                .buy(FruitType.APPLE, 1)//10
//                .buy(FruitType.STRAWBERRY, 2)//测试边界值99.99
                .buy(FruitType.STRAWBERRY, 2.2)//测试边界值101.99
                .buy(FruitType.MANGO, 6.999)
                .build();

        BigDecimal totalAmount = userD.checkout();
        System.out.println("用户D没参加活动前需要付款：" + totalAmount);

        totalAmount = (BigDecimal) PromotionFactory.doPromotion(DEFAULT_PROMOTION, totalAmount);

        System.out.println("用户D参加满100减10活动后需要付款：" + totalAmount);

        /*
        * 用户D没参加活动前需要付款：99.99
            用户D参加满100减10活动后需要付款：99.99
        *
        * 用户D没参加活动前需要付款：101.99
        * 用户D参加满100减10活动后需要付款：91.99
        **/
    }
}